import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-11-21
 * Time: 22:18
 */
public class TestTree {
    public static List<String> menu() {
        List<String> list = new ArrayList<>();
        list.add("1. 先序创建二叉树");
        list.add("2. 层序创建二叉树");
        list.add("3. 先中后序递归遍历");
        list.add("4. 先中后序非递归遍历");
        list.add("5. 层序遍历");
        list.add("6. 求二叉树节点个数");
        list.add("7. 求二叉树叶子节点个数");
        list.add("8. 求二叉树度为1的节点个数");
        list.add("9. 求二叉树度为2的节点个数");
        list.add("10. 二叉树深度");
        list.add("11. 交换左右子树");
        return list;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        TaskOfDS_BinaryTree taskOfDS_binaryTree = new TaskOfDS_BinaryTree();
        TaskOfDS_BinaryTree.TreeNode root = new TaskOfDS_BinaryTree.TreeNode();
        while (true) {
            List<String> list = menu();
            for (String s : list) {
                System.out.println(s);
            }
            System.out.println("请输入需要执行的步骤: ");
            int n = in.nextInt();
            switch (n) {
                case 1:
                    System.out.print("请输入先序遍历序列: ");
                    String str = in.next();
                    root = taskOfDS_binaryTree.createTreePreOrder(str);
                    break;
                case 2:
                    System.out.print("请输入层序遍历序列: ");
                    str = in.next();
                    root = taskOfDS_binaryTree.createTreeLevelOrder(str);
                    break;
                case 3:
                    System.out.print("先序遍历(递归): ");
                    taskOfDS_binaryTree.preOrder(root);
                    System.out.println();
                    System.out.print("中序遍历(递归): ");
                    taskOfDS_binaryTree.inOrder(root);
                    System.out.println();
                    System.out.print("后序遍历(递归): ");
                    taskOfDS_binaryTree.postOrder(root);
                    System.out.println();
                    System.out.println("============================");
                    break;
                case 4:
                    System.out.print("先序遍历: ");
                    taskOfDS_binaryTree.preorderTraversalNor(root);
                    System.out.println();
                    System.out.print("中序遍历: ");
                    taskOfDS_binaryTree.inorderTraversalNor(root);
                    System.out.println();
                    System.out.print("后序遍历: ");
                    taskOfDS_binaryTree.postorderTraversalNor(root);
                    System.out.println();
                    System.out.println("============================");
                    break;
                case 5:
                    System.out.println("层序遍历");
                    taskOfDS_binaryTree.levelOrder(root);
                    System.out.println();
                    System.out.println("============================");
                    break;
                case 6:
                    System.out.print("二叉树节点个数:");
                    System.out.println(taskOfDS_binaryTree.size(root));
                    break;
                case 7:
                    System.out.print("二叉树叶子节点个数:");
                    System.out.println(taskOfDS_binaryTree.getLeafNodeCount(root));
                    break;
                case 8:
                    System.out.print("二叉树度为1节点个数:");
                    System.out.println(taskOfDS_binaryTree.getDegreeIs1(root));
                    break;
                case 9:
                    System.out.print("二叉树度为2节点个数:");
                    System.out.println(taskOfDS_binaryTree.getDegreeIs2(root));
                    break;
                case 10:
                    System.out.print("二叉树的深度:");
                    System.out.println(taskOfDS_binaryTree.getHeight(root));
                    break;
                case 11:
                    System.out.println("交换左右子树");
                    taskOfDS_binaryTree.swap(root);
                    break;
                default:
                    System.out.println("输入错误, 请重新输入!");
            }
        }

    }
}
